package miansi;

import java.util.Scanner;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2024/10/19-下午3:46
 * Since  :   1.0
 * Version:   1.0
 */


public class xiaomi {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a=scanner.nextInt();
        while (a>0){
            String s=scanner.next();
            String  t=scanner.next();
            String p=scanner.next();
            String result = toGuiFan(s, t, p);
            System.out.println(result);
            a--;
        }

    }

    public  static String  toGuiFan(String s,String t,String p){
        int count=0;
        while (s.contains(t)){
            int index = s.indexOf(t);
            s=s.substring(0,index) +s.substring(index+t.length());
            s+=p;
            count++;
            if (count==1000){
                return "-1";
            }
        }
        return s;

    }
}
